
<%@page import="java.util.List"%>
<%@page import="java.util.ArrayList"%>
<%@page import="emp.*,java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>emplist</title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>
	<body>
		<div id="wrap">
			<div id="top_content">
			<%@include file="header.jsp" %>
				<div id="content">
					<p id="whereami">
					</p>
					<h1>
						Welcome!
					</h1>
					<table class="table">
						<tr class="table_header">
							<td>
								ID
							</td>
							<td>
								Name
							</td>
							<td>
								Salary
							</td>
							<td>
								Age
							</td>
							<td>
								Operation
							</td>
						</tr>

						<%
							List<Emp> list = new ArrayList<Emp>();
							try {
								String sql = "select * from t_emp";
								Connection con = DBUtil.openInThread();
								Statement stm = con.createStatement();
								ResultSet rs = stm.executeQuery(sql);

								while (rs.next()) {
									Emp e = new Emp();
									e.setId(rs.getInt("id"));
									e.setName(rs.getString("name"));
									e.setSalary(rs.getDouble("salary"));
									e.setAge(rs.getInt("age"));
									list.add(e);
								}
								DBUtil.close(null, stm, rs);
							} catch (Exception e) {
								e.printStackTrace();
							} finally {
								DBUtil.closeInThread();
							}
							for (int i = 0; i < list.size(); i++) {
								Emp e = list.get(i);
						%>
						<tr class="row<%=i % 2 + 1%>">
							<td>
								<%=e.getId()%>
							</td>
							<td>
								<%=e.getName()%>
							</td>
							<td>
								<%=e.getSalary()%>
							</td>
							<td>
								<%=e.getAge()%>
							</td>
							<td>
								<a href="emplist.html">delete emp</a>&nbsp;
								<a href="updateEmp.html">update emp</a>
							</td>
						</tr>
						<%
							}
						%>

					</table>
					<p>
						<input type="button" class="button" value="Add Employee"
							onclick="location='addEmp.html'" />
					</p>
				</div>
			</div>
			<%@include file="footer.jsp" %>
		</div>
	</body>
</html>
